<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .box{
            position:relative;
            width: 200px;
            height: 100px;
            background-color: skyblue;
            user-select: none;
        }
        .info{
            width: 200px;
            height: 200px;
            position:absolute;
            display: none;
            background-color: red;

            /* 让鼠标事件在这个元素上失效，防止出现抖动问题。因为我们这个案例是根据父元素的offsetX、Y对于子元素的margin进行赋值的。如果因为某些因素导致鼠标跑到子元素上了，那么我们上节课讲过，这会导致offsetX、Y会根据子元素的左上角去定位，那这时候这个子元素的位置可就乱套了 */
            pointer-events: none;
        }
    </style>
</head>
<body>
    <div class="box">
        鼠标放这里即可查看名字
        <div class="info">我是mikaisa</div>
    </div>
    <script>
        const box = document.querySelector('.box')
        const info = document.querySelector('.info')

        box.onmousemove = (e)=>{
            info.style.display = 'block'
            info.style.marginLeft = e.offsetX + 'px'
            info.style.marginTop = e.offsetY + 'px'
        }

        box.onmouseout = (e)=>{
            info.style.display = 'none'
        }
    </script>
</body>
</html>